package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.SysOrgCertificate;
import com.ruoyi.system.service.ISysOrgCertificateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 机构资质Controller
 *
 * @author ruoyi
 * @date 2023-02-07
 */
@Api(tags = "机构资质")
@RestController
@RequestMapping("/certificate")
public class SysOrgCertificateController extends BaseController {
    @Autowired
    private ISysOrgCertificateService sysOrgCertificateService;

    /**
     * 查询机构资质列表
     */
    @RequiresPermissions("system:certificate:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询机构资质列表", response = SysOrgCertificate.class)
    public TableDataInfo list(SysOrgCertificate sysOrgCertificate) {
        startPage();
        List<SysOrgCertificate> list = sysOrgCertificateService.selectSysOrgCertificateList(sysOrgCertificate);
        return getDataTable(list);
    }

    /**
     * 导出机构资质列表
     */
    @RequiresPermissions("system:certificate:export")
    @Log(title = "导出机构资质列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出机构资质列表")
    public void export(HttpServletResponse response, SysOrgCertificate sysOrgCertificate) {
        List<SysOrgCertificate> list = sysOrgCertificateService.selectSysOrgCertificateList(sysOrgCertificate);
        ExcelUtil<SysOrgCertificate> util = new ExcelUtil<SysOrgCertificate>(SysOrgCertificate.class);
        util.exportExcel(response, list, "机构资质数据");
    }

    /**
     * 获取机构资质详细信息
     */
    @RequiresPermissions("system:certificate:query")
    @GetMapping(value = "/{certificateId}")
    @ApiOperation(value = "获取机构资质详细信息", response = SysOrgCertificate.class)
    public AjaxResult getInfo(@ApiParam(value = "资质id", required = true) @PathVariable("certificateId") Long certificateId) {
        return success(sysOrgCertificateService.selectSysOrgCertificateByCertificateId(certificateId));
    }

    /**
     * 新增机构资质信息
     */
    @RequiresPermissions("system:certificate:add")
    @Log(title = "新增机构资质", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增机构资质")
    public AjaxResult add(@RequestBody SysOrgCertificate sysOrgCertificate) {
        return toAjax(sysOrgCertificateService.insertSysOrgCertificate(sysOrgCertificate));
    }

    /**
     * 修改机构资质
     */
    @RequiresPermissions("system:certificate:edit")
    @Log(title = "修改机构资质", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改机构资质")
    public AjaxResult edit(@RequestBody SysOrgCertificate sysOrgCertificate) {
        return toAjax(sysOrgCertificateService.updateSysOrgCertificate(sysOrgCertificate));
    }

    /**
     * 删除机构资质
     */
    @RequiresPermissions("system:certificate:remove")
    @Log(title = "删除机构资质", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{certificateIds}")
    @ApiOperation(value = "删除机构资质")
    public AjaxResult remove(@ApiParam(value = "资质id", required = true) @PathVariable String[] certificateIds) {
        return toAjax(sysOrgCertificateService.deleteSysOrgCertificateByCertificateIds(certificateIds));
    }
}
